<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>back-staff</title>
    <link rel="stylesheet" href="/admin/layui-v2.4.5/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="/admin/css/admin.css"  media="all">
</head>
<body>
<script src="/admin/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/admin/js/jquery.js"></script>

<!--<div class="demoTable">-->
    <!--OfcId查询：-->
    <!--<div class="layui-inline">-->
        <!--<input class="layui-input" name="keyword" id="select0fcId" autocomplete="off"style="display:inline-block">-->
    <!--</div>-->
    <!--<button class="layui-btn" data-type="reload"lay-submit lay-filter="searchOfcId">查询</button>-->
<!--</div>-->

<table class="layui-hide" id="demo" lay-filter="demo"></table>

<!--弹出层-->
<div class="layui-row" id="testUser" style="display: none;">
    <div class="layui-col-md10">
        <form class="layui-form"lay-filter="formTestFilter" id="addUserForm">
            <div class="layui-form-item">
                <label class="layui-form-label">选择科室</label>
                <div class="layui-input-block">
                    <select name="ofc_id" lay-verify="required" id="departMent" lay-filter="office-select">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员账号：</label>
                <div class="layui-input-block">
                    <input type="text" id="ad_num" name="ad_num" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员密码：</label>
                <div class="layui-input-block">
                    <input type="text" id="ad_password" name="ad_password" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员备注：</label>
                <div class="layui-input-block">
                    <input type="text" id="ad_remark" name="ad_remark" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员权限：</label>
                <div class="layui-input-block">
                    <select class="layui-input" name="ad_power" id="ad_power">
                        <option value="1">超级管理员</option>
                        <option value="0" selected="">普通管理员</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员姓名：</label>
                <div class="layui-input-block">
                    <input type="text"id="ad_name" name="ad_name" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="demo1" lay-filter="demo1">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>


<script type="text/javascript">
    layui.use([  'table','form','layer'], function() {
        var $ = layui.jquery
            ,table = layui.table //表格
            , form = layui.form //表单
            , layer = layui.layer //弹层
            ,index = parent.layer.getFrameIndex(window.name)

        //执行一个 table 实例
        table.render({
            elem: '#demo'
            , height: 420
            , url: '/hospital/user' //数据接口
            , id: '#testReload'
            , title: '用户表'
            , limit: 10
            , method: 'post'
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                    ,limits:[10,20]
                    , jump: function (obj) {
                        console.log(obj)
                    }}
            , toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            // ,totalRow: true //开启合计行
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'ad_num', title: '管理员账号', sort: true}
                , {field: 'ad_password', title: '管理员密码'}
                , {field: 'ad_remark', title: '管理员备注'}
                , {field: 'ad_power', title: '管理员权限 ', sort: true}
                , {field: 'ad_name', title: '管理员姓名 '}
                // ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
            ]]
        });


        // //搜索查询
        // form.on('submit(searchOfcId)', function (data) {
        //     var field = data.field;
        //     var b = $(" #selectOfcId ");
        //     contentType:'application/json;charset=UTF-8';
        //     type: 'post';
        //     table.reload('demo', {
        //
        //         page: {
        //             curr: 1 //重新从第 1 页开始
        //         }
        //         , where: {
        //             'id': b.val()
        //         }
        //
        //     });
        // });

        //下拉框
        layui.use('form', function(){
            var form = layui.form;
            form.render('select');
        });

        $(function () {
            fn();
        });

        function fn() {

            $.ajax({
                ansyc: false,
                url: "/hospital/patient/register/office/get",
                type: "GET",
                // contentType:"application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    layui.use('form', function () {
                        var form = layui.form;
                        $("#departMent").html("");
                        $("#departMent").append("<option value=''>请选择科室</option>");
                        $.each(data, function (index, ele) {

                            $("#departMent").append("<option value='" + ele.officeId + "'>" + ele.officeName + "</option>");
                        });
                        form.render('select');
                    });

                },
                error: function () {
                    alert("数据加载失败！");
                }
            });

        }


        //监听提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '提交信息'
            })
           // return false;//提交后不关闭弹窗
        });



        //监听头工具栏事件
        table.on('toolbar(demo)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据

          console.log(data)
            if (obj.event === 'add') {//layer.msg('添加');

                layer.open({
                    type: 2,
                    title: "添加人员",
                    area: ['500px', '450px'],
                    fixed: false,
                    maxmin: true,
                    shadeClose: true,
                    content: 'back-user.html'
                });


            } else if (obj.event === 'update') {
                if (data.length === 0) {
                    layer.msg('请选择一行');
                } else if (data.length > 1) {
                    layer.msg('只能同时编辑一个');
                } else {
                    layer.open({
                        type: 2,
                        title: "编辑人员",
                        maxmin : true,
                        area: ['70%', '70%'],
                        shadeClose: true,
                        content:'back-update.html'

                    });
                }
            } else if (obj.event === 'delete') {
                if (data.length === 0) {
                    layer.msg('请选择一行');
                } else {
                    layer.confirm('真的删除吗?', function (index) {
                        $.ajax({
                            url: "/hospital/deleteUser",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            data: JSON.stringify({
                                "key": data
                            }),
                            success: function (e) {
                                if (e.code == 1) {
                                    layer.msg("删除成功");
                                } else {
                                    layer.msg("删除失败");
                                }
                            },
                            error: function (e) {
                                layer.msg(e);
                            }
                        })

                        table.reload('demo');//就会读取后台数据,重新加载；
                        layer.msg('已删除');
                    });
                }
            }



        });




    });

</script>
</body>
</html>
